public class MyQueue {
    static class ListNode{
        int val;
        ListNode next;
        public ListNode(int val){
            this.val = val;
        }
    }
    private int usedSize;
    public ListNode head;
    public ListNode tail;
    public void offer(int val){
        ListNode newNode = new ListNode(val);
        if(head == null){
            head = newNode;
            tail = newNode;
        }else {
            tail.next = newNode;
            tail = newNode;
        }
        usedSize++;
    }
    public int getUsedSize(){
        return usedSize;
    }
    public int poll(){
        if(head == null){
            return -1;
        }
        int val = head.val;
        if(head.next == null){
            head = null;
            tail = null;
            usedSize--;
            return val;
        }
        head = head.next;
        usedSize--;
        return val;
    }
    public int peek(){
        if(head == null){
            return -1;
        }
        return head.val;
    }
}
